<?php
class Express_record_model extends BZ_Model
{
    protected $table = 'express_record';

    public function updateBak($postData)
    {
        $data = array(
            'ischeck'   => $postData->ischeck,
            'state'     => $postData->state,
            'context'   => json_encode($postData->data),
            'update_at' => date('Y-m-d H:i:s'),
        );
        $this->db->where('number', $postData->nu);
        $this->db->where('company', $postData->com);
        return $this->db->update($this->table, $data);
    }

    public function page_list($page_num, $num, $param)
    {
        $this->db->select('id,name,company,number,context,ischeck,state,create_at');
        $this->db->from($this->table);
        if(!empty($param['company'])){
            $this->db->like('company', $param['company']);
        }

        if(!empty($param['number'])){
            $this->db->where('number', $param['number']);
        }
        $this->db->order_by('id', 'DESC');
        $this->db->limit($page_num, $num);
        return $this->db->get();
    }

    public function total($param)
    {
        $this->db->select('*');
        $this->db->from($this->table);
        if(!empty($param['company'])){
            $this->db->like('company', $param['company']);
        }

        if(!empty($param['number'])){
            $this->db->where('number', $param['number']);
        }
        return $this->db->count_all_results();
    }

    public function findById($id)
    {
        $this->db->select('id,name,company,number,context,ischeck,state,create_at');
        $this->db->from($this->table);
        $this->db->where('id', $id);
        $this->db->limit(1);
        return $this->db->get();
    }

    public function findByNu($number)
    {
        $this->db->select('id,name,company,number,context,ischeck,state,create_at');
        $this->db->from($this->table);
        $this->db->where('number', $number);
        $this->db->limit(1);
        return $this->db->get();
    }



}